var a = require("../../../@babel/runtime/helpers/defineProperty"), t = require("../../../mybehaviors/location/location"), e = getApp();

Component({
    behaviors: [ t ],
    properties: {
        datas: {
            type: null
        },
        component_id: {
            type: null
        },
        U_tabcontrol: {
            type: null
        },
        btnFlag: {
            type: null
        },
        bottomShowBolIndex: {
            type: null
        },
        index: {
            type: null
        },
        plugin_active: String
    },
    data: {
        emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
        clientWidth: "375",
        active: "0",
        titleName: [ {
            id: "business_merchant",
            text: "商家",
            url: "plugin.store-cashier.frontend.store.store.get-store-list-to-page"
        }, {
            id: "business_discount",
            text: "折扣",
            url: "plugin.universal-card.frontend.store-discount.store-data"
        }, {
            id: "business_coupon",
            text: "优惠券",
            url: "plugin.store-cashier.frontend.store.aggregate-page.coupon"
        }, {
            id: "business_goods_gift",
            text: "礼包",
            url: "plugin.store-cashier.frontend.store.aggregate-page.goods-gift"
        } ],
        api: "",
        dataJson: {},
        pd_classfy_arr: [],
        pd_date_arr: [],
        pd_index: 0,
        pd_date_index: 0,
        shopList0: [],
        isLoadMore0: !1,
        page0: 1,
        total_page0: 0,
        shopList1: [],
        isLoadMore1: !1,
        page1: 1,
        total_page1: 0,
        shopList2: [],
        isLoadMore2: !1,
        page2: 1,
        total_page2: 0,
        shopList3: [],
        isLoadMore3: !1,
        page3: 1,
        total_page3: 0,
        pd_date: {},
        showMun: !0,
        openTemplate: 0,
        datas_style02: {
            get_number: 999,
            preview_color: "#f5f5f5",
            font_size: 14,
            font_color: "#666666",
            border_radius: 35,
            class_font_size: 12,
            class_font_color: "#f08316",
            class_bg_color: "#fff",
            class_border_radius: 5,
            location_font_size: 14,
            location_font_color: "#666666",
            discount_font_size: 10,
            discount_title_color: "#ffffff",
            discount_font_color: "#666666",
            discount_list: [ "1", "2", "3", "4" ],
            tag_font_size: 10,
            tag_font_color: "#fff",
            tag_bg_color: "#f08316",
            tag_border_color: "#f08316",
            tag_border_radius: 5,
            show_goods: !0,
            tab_list: [],
            tab_bg_color: "#ffffff",
            tab_color: "#333333",
            tab_active_color: "#ff8400"
        }
    },
    lifetimes: {
        attached: function() {
            var a = wx.getStorageSync("langIndex");
            this.setData({
                language: a.en
            });
        },
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        var a = this;
        this.data.datas.discount_list.indexOf("1") > -1 ? this.setData({
            showMun: !0
        }) : this.data.datas.discount_list.indexOf("1") < 0 && this.setData({
            showMun: !1
        }), this.setData({
            clientWidth: wx.getSystemInfoSync().windowWidth
        }), this._getLocation(function(t) {
            console.log(t), a.data.U_tabcontrol || a.data.datas.tab_list.indexOf("1") > -1 ? a.chooseTab(" ", "business_merchant") : a.data.datas.tab_list.indexOf("2") > -1 ? a.chooseTab(" ", "business_discount") : a.data.datas.tab_list.indexOf("3") > -1 ? a.chooseTab(" ", "business_coupon") : a.data.datas.tab_list.indexOf("4") > -1 && a.chooseTab(" ", "business_goods_gift");
        }, function(t) {
            a.data.U_tabcontrol || a.data.datas.tab_list.indexOf("1") > -1 ? a.chooseTab(" ", "business_merchant") : a.data.datas.tab_list.indexOf("2") > -1 ? a.chooseTab(" ", "business_discount") : a.data.datas.tab_list.indexOf("3") > -1 ? a.chooseTab(" ", "business_coupon") : a.data.datas.tab_list.indexOf("4") > -1 && a.chooseTab(" ", "business_goods_gift");
        }), console.log(wx.getStorageSync("address-point"), "sssssssssssssss");
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        toRouter: function(a) {
            var t = a.currentTarget.dataset.item;
            1 == t.specify_show ? wx.navigateTo({
                url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + t.id + "&fromHome=1"
            }) : 1 == t.store_decorate ? wx.navigateTo({
                url: "/packageG/o2o/HomeSeller/HomeSeller?store_id=" + t.id
            }) : wx.navigateTo({
                url: "/packageC/o2o/HomeSeller/HomeSeller?store_id=" + t.id
            });
        },
        toClassify: function(a) {
            var t = a.currentTarget.dataset.id, e = a.currentTarget.dataset.name;
            wx.navigateTo({
                url: "/packageC/o2o/o2oCategory/o2oCategory?id=" + t + "&city=" + this.data.city + "&point=" + JSON.stringify(this.data.point) + "&name=" + e
            });
        },
        toGoods: function(a) {
            var t = a.currentTarget.dataset.item;
            wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + t.goods_id
            });
        },
        pdClassfySearch: function(a) {
            var t = a.currentTarget.dataset.index, e = a.currentTarget.dataset.id;
            this.setData({
                pd_index: t
            }), this.setData({
                pd_category_id: e
            }), this.pdInitData(), this.getPdData();
        },
        pdInitData: function() {
            this.setData({
                isLoadMore1: !1,
                page1: 1,
                total_page1: 0,
                shopList1: []
            });
        },
        pdDateSearch: function(a) {
            var t = a.currentTarget.dataset.index, e = a.currentTarget.dataset.date;
            this.setData({
                pd_date_index: t
            }), this.setData({
                pd_date: e
            }), this.pdInitData(), this.getPdData();
        },
        getCoupon: function(a) {
            var t = a.currentTarget.dataset.id, s = e.getNetAddresss("plugin.store-cashier.frontend.store.coupon-get");
            e._getNetWork({
                url: s,
                data: {
                    coupon_id: t
                },
                success: function(a) {
                    var t = a.data;
                    1 == t.result ? wx.showModal({
                        title: "提示",
                        content: "领取成功",
                        showCancel: !1,
                        success: function(a) {}
                    }) : wx.showToast({
                        title: t.msg,
                        icon: "none",
                        duration: 1500
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        },
        gotoShop: function(a) {
            var t = a.currentTarget.dataset.id;
            wx.navigateTo({
                url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + t
            });
        },
        goToAdress: function(a) {
            var t = a.currentTarget.dataset.items.latitude, s = a.currentTarget.dataset.items.longitude, o = a.currentTarget.dataset.items.store_name, i = e.BMapTransqqMap(parseFloat(s), parseFloat(t));
            wx.openLocation({
                latitude: i.lat,
                longitude: i.lng,
                scale: 18,
                name: o
            });
        },
        getMoreList: function() {
            var t, s = this;
            if (this.setData(a({}, "isLoadMore".concat(this.data.tab), !1)), !(this.data["page".concat(this.data.tab)] >= this.data["total_page".concat(this.data.tab)])) {
                switch (this.data["page".concat(this.data.tab)] = this.data["page".concat(this.data.tab)] + 1, 
                this.data.tab) {
                  case 0:
                    t = e.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat)), 
                    this.setData({
                        dataJson: {
                            lng: t.lng ? t.lng : "",
                            lat: t.lat ? t.lat : "",
                            city_name: this.data.city,
                            page: this.data.page0
                        }
                    });
                    break;

                  case 2:
                    this.setData({
                        dataJson: {
                            page: this.data.page2
                        }
                    });
                    break;

                  case 3:
                    this.setData({
                        dataJson: {
                            page: this.data.page3
                        }
                    });
                }
                var o = [];
                this.data.datas.list && this.data.datas.list.length > 0 && (this.data.datas.list.forEach(function(a) {
                    o.push(a.id);
                }), this.data.dataJson.category_ids = o);
                var i = e.getNetAddresss(s.data.api);
                e._postNetWork({
                    url: i,
                    data: s.data.dataJson,
                    success: function(t) {
                        var e = t.data;
                        if (1 == e.result) {
                            var o, i;
                            if (1 !== s.data.tab) s.setData((a(o = {}, "shopList".concat(s.data.tab), s.data["shopList".concat(s.data.tab)].concat(e.data.data)), 
                            a(o, "total_page".concat(s.data.tab), e.data.last_page), o));
                            if (s.data["page".concat(s.data.tab)] >= s.data["total_page".concat(s.data.tab)] ? s.setData(a({}, "isLoadMore".concat(s.data.tab), !1)) : s.setData(a({}, "isLoadMore".concat(s.data.tab), !0)), 
                            0 == s.data.tab) if (s.data["shopList".concat(s.data.tab)].length > s.data.datas.get_number) s.data["shopList".concat(s.data.tab)].splice(s.data.datas.get_number, s.data["shopList".concat(s.data.tab)].length - s.data.datas.get_number), 
                            console.log(s.data["shopList".concat(s.data.tab)], "aaaaaaaaa"), s.setData((a(i = {}, "shopList".concat(s.data.tab), s.data["shopList".concat(s.data.tab)]), 
                            a(i, "isLoadMore".concat(s.data.tab), !1), i));
                            s.triggerEvent("setLoadMore", {
                                isLoadMore: s.data["isLoadMore".concat(s.data.tab)]
                            });
                        } else {
                            var d;
                            s.setData((a(d = {}, "page".concat(s.data.tab), [ "page".concat(s.data.tab) ] - 1), 
                            a(d, "isLoadMore".concat(s.data.tab), !1), d));
                        }
                    },
                    fail: function(a) {
                        console.log(a);
                    }
                });
            }
        },
        onClick: function(a) {
            this.setData({
                active: a.detail.name
            }), this.chooseTab("", a.detail.name, "tag");
        },
        chooseTab: function(t, s, o) {
            var i;
            o ? this.setData({
                tab: Number(s)
            }) : this.setData({
                tab: this.data.titleName.findIndex(function(a) {
                    return a.id == s;
                })
            }), this.setData({
                api: this.data.titleName[this.data.tab].url
            });
            var d = this.data.titleName[this.data.tab].id;
            if (this.setData((a(i = {}, "isLoadMore".concat(this.data.tab), !1), a(i, "total_page".concat(this.data.tab), 0), 
            a(i, "page".concat(this.data.tab), 1), i)), "business_merchant" === d) {
                var n = e.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat));
                this.setData({
                    dataJson: {
                        lng: n.lng ? n.lng : "",
                        lat: n.lat ? n.lat : "",
                        city_name: this.data.city,
                        page: this.data.page0
                    }
                });
            } else switch (d) {
              case "business_discount":
                this.setData({
                    dataJson: {
                        page: this.data.page1
                    }
                });
                break;

              case "business_coupon":
                this.setData({
                    dataJson: {
                        page: this.data.page2
                    }
                });
                break;

              case "business_goods_gift":
                this.setData({
                    dataJson: {
                        page: this.data.page3
                    }
                });
            }
            var r = [];
            this.data.datas.list && this.data.datas.list.length > 0 && (this.data.datas.list.forEach(function(a) {
                r.push(a.id);
            }), this.data.dataJson.category_ids = r), this.getList();
        },
        getList: function() {
            var t = this, s = e.getNetAddresss(t.data.api);
            e._postNetWork({
                url: s,
                data: this.data.dataJson,
                success: function(e) {
                    var s = e.data;
                    if (1 == s.result) {
                        var o, i;
                        if (1 === t.data.tab) t.setData({
                            pd_classfy_arr: s.data.store_category,
                            pd_date_arr: s.data.date_time
                        }), t.setData({
                            pd_category_id: s.data.store_category[0].id,
                            pd_date: s.data.date_time[0]
                        }), t.getPdData(); else t.setData((a(o = {}, "shopList".concat(t.data.tab), s.data.data), 
                        a(o, "total_page".concat(t.data.tab), s.data.last_page), o));
                        if (t.data["total_page".concat(t.data.tab)] <= 1 ? t.setData(a({}, "isLoadMore".concat(t.data.tab), !1)) : t.setData(a({}, "isLoadMore".concat(t.data.tab), !0)), 
                        0 == t.data.tab) if (t.data["shopList".concat(t.data.tab)].length > t.data.datas.get_number) t.data["shopList".concat(t.data.tab)].splice(t.data.datas.get_number, t.data["shopList".concat(t.data.tab)].length - t.data.datas.get_number), 
                        t.setData((a(i = {}, "shopList".concat(t.data.tab), s.data.data), a(i, "isLoadMore".concat(t.data.tab), !1), 
                        i));
                        s.data.hasOwnProperty("store_list_style") && t.setData({
                            openTemplate: s.data.store_list_style || 0
                        });
                    } else console.log(s.msg);
                },
                fail: function(a) {
                    console.log(a), wx.showToast({
                        title: a.msg,
                        duration: 1e3,
                        icon: "none"
                    });
                }
            });
        },
        getPdData: function() {
            var a = this, t = e.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat)), s = {
                lng: t.lng,
                lat: t.lat,
                city_name: this.data.city,
                page: this.data.page1,
                week: this.data.pd_date.week_num,
                category_id: this.data.pd_category_id,
                day: this.data.pd_date.day
            }, o = e.getNetAddresss("plugin.universal-card.frontend.store-discount.privilege");
            e._getNetWork({
                url: o,
                data: s,
                success: function(t) {
                    var e = t.data;
                    1 == e.result ? (a.setData({
                        total_page1: e.data.last_page,
                        shopList1: e.data.data
                    }), a.data.total_page1 <= 1 ? a.setData({
                        isLoadMore1: !1
                    }) : a.setData({
                        isLoadMore1: !0
                    })) : a.setData({
                        isLoadMore1: !1
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    }
});